package app.objectstoragedemo.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.time.LocalDateTime;

// 数据库 公共字段 自动填充 数据
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    /***
     * MybatisPlus 自动填充
     * insertFill 为插入数据 时触发
     * updateFill 为修改数据 时触发
     */

    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("createTime", Instant.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updatedAt", LocalDateTime.now());
    }
}
